Skip to content

csnode: don't keep an uncertain block's rewards when the trusted mask differs - #9

Merged
EnzinoBB merged 2 commits into
masterfrom
fix/uncertain-block-trusted-mask
Oct 9, 2026
Merged

EnzinoBB merged 2 commits into
masterfrom
fix/uncertain-block-trusted-mask

Conversation

@EnzinoBB

@EnzinoBB EnzinoBB commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

When a node's own last block turns out to be "uncertain" (its hash is not the one the network signed), BlockChain::storeBlock() fetches the canonical block. If testContentEqual() says the content is the same, the node swaps it in place (deferredBlock_ = pool) without touching the wallet caches.

testContentEqual() ignored the trusted mask (numberTrusted/realTrusted), which is exactly what decides which confidants receive the reward and the fees (fundConfidantsWalletsWitnReward, fundConfidantsWalletsWithFee). A trusted node that built block N with its own mask (e.g. a confidant whose stage-3 was lost locally, marked untrusted) kept the rewards credited under that mask, while every other node credits them under the canonical mask. The difference is permanent and silent, and it builds up on the wallets of frequent trusted nodes.

This is a plausible cause of the balance divergence that left nodes stuck at block 176'776'210: a validator's reward withdrawal was rejected by graph validation on nodes holding a lower balance.

Fix (+2 lines in blockchain.cpp)

The trusted mask is now part of the compared content. When it differs, storeBlock takes the existing "different content" branch: removeLastBlock() reverts the node's own block from the caches with its own mask (a mirror operation), and the canonical block is then applied through normal sync. No protocol or consensus rule changes.

testContentEqual() is made public so it can be unit-tested.

Tests

Before After
BlockChain.ContentEqualRequiresSameTrustedMask fails (different masks judged "equal") ✅
full nodetests — 119/119

Notes

  • Nodes that already diverged are not repaired: they need a full slow start.
  • The timestamp stays out of the comparison: it only affects delegation expiry, which catches up on the next block.
  • A single commit that applies as is to CREDITSCOM/node (identical files).

🤖 Generated with Claude Code

EnzinoBB and others added 2 commits October 8, 2026 13:29
… differs

When a node's own last block turns out to be "uncertain" (its hash is not
the one the network signed), BlockChain::storeBlock() fetches the canonical
block. If testContentEqual() says the two have the same content, the node
swaps it in place (deferredBlock_ = pool) without touching the wallet caches.

testContentEqual() ignored the trusted mask (numberTrusted/realTrusted). That
mask decides which confidants receive the block reward and the fees
(WalletsCache::Updater: fundConfidantsWalletsWitnReward,
fundConfidantsWalletsWithFee). So a trusted node that built block N with its
own mask (e.g. a confidant whose stage-3 it lost marked as untrusted) kept the
rewards and fees credited under that mask, while every other node credits
them under the canonical mask. The difference is permanent and silent, and it
accumulates on the wallets of frequent trusted nodes. This is a plausible
source of the balance divergence that left nodes stuck at block 176'776'210
(a validator withdrawing its rewards was rejected by "graph validation" on
nodes holding a lower balance).

Include the trusted mask in the compared content. When it differs, storeBlock
takes the existing "different content" branch: removeLastBlock() reverts the
own block from the caches with its own mask, and the canonical block is then
applied through the normal sync path. No protocol or consensus rule changes.

testContentEqual() is made public so it can be unit-tested.

Test: BlockChain.ContentEqualRequiresSameTrustedMask fails before the fix.
nodetests: 119/119 pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	tests/csnode/blockchain_tests.cpp
@EnzinoBB
EnzinoBB merged commit 3856277 into master Oct 9, 2026
1 check passed
EnzinoBB added a commit that referenced this pull request Nov 5, 2026
- setup-test: "tokens node" passes --node-key too. The wallet no longer takes
  the node's key from the current folder (wallet PR #7), and this wallet.toml
  says node_key = "off" (the answer was create), so "node" did not resolve and
  the {"error": ...} JSON ended in KeyError 'source'. The error is now asserted
  first.
- setup.ps1: the command printed for later quotes only the arguments that need
  it (".\credits-wallet.exe --config wallet.toml account new main"), as
  setup.sh does; the test looks for "account new main".
- both: the create option says the account is under the wallet password, one
  for every account, chosen with the first (wallet PRs #9/#10).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant